package cst.a729yt.startproject_729yt;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import cst.a729yt.startproject_729yt.bean.Weatherlnfo;
import cst.a729yt.startproject_729yt.listener.WeatherListener;
import cst.a729yt.startproject_729yt.model.WeatherModel;

public class MainActivity extends AppCompatActivity {
    private EditText city_edit;
    private Button btn_1;
    private TextView city_text;
    private TextView wd_text;
    private WeatherModel model;
    private WeatherListener listener;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        city_edit = (EditText) findViewById(R.id.city_edit);
        btn_1=(Button)findViewById(R.id.btn_1);
        city_text =(TextView)findViewById(R.id.city_text);
        city_text =(TextView)findViewById(R.id.wd_text);
        listener=new WeatherListener() {
            @Override
            public void onResponse(Weatherlnfo w) {
                city_text.setText(w.getCity());
                wd_text.setText(w.getTemp());
            }

            @Override
            public void onFail(String msg) {
                city_text.setText("解析错误");
            }
        };

        btn_1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                model=new WeatherModel();
                model.getWeather(city_edit.getText().toString(),listener);
            }
        });

    }




}
